home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93a.txt / 000029_icon-group-sender _Mon Jan 18 08:43:05 1993.msg < prev    next >
Internet Message Format  |  1993-04-21  |  5KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 18 Jan 1993 11:23:36 MST
  2. Message-Id: <9301181543.AA01233@turing.cse.nau.edu>
  3. From: sbw@turing.cse.nau.edu (Steve Wampler)
  4. Date: Mon, 18 Jan 1993 08:43:05 MST
  5. In-Reply-To: Michael Sperber's mail message of Jan 18,  1:52pm.
  6. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  7. To: sperber@soir.informatik.uni-tuebingen.de (Michael Sperber)
  8. Subject: Re: Pattern matching in Icon?
  9. Cc: icon-group@cs.arizona.edu
  10. Status: R
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12.  
  13. On Jan 18 at  1:52pm, Michael Sperber writes:
  14. } Well, at least one person got it (partially) right.  I had't
  15. } thought of Prolog as the inspiration for the control structure
  16. } I had proposes, but in fact, a unification is what would happen
  17. } in pattern matching, albeit in a much more limited sense, that
  18. } is also easier and more straightforward to implement.
  19.  
  20. } As I keep saying (jeez, has NOONE here ever looked at Hope, Miranda,
  21. } ML or the like?!), the proposed scheme could be used to
  22. } implement structural recursion VERY elegantly - with the
  23. } added power of generators.
  24.  
  25. But - you seem to be saying that the language designer is going to
  26. implement *exactly* the pattern matching facility you want in
  27. *exactly* the right way - once you add something like that to
  28. a language, it's *very* hard to change!  What I'm saying is
  29. that Icon already has a facility that can not only do everything
  30. you want, with really very little effort (you write your pattern-matching
  31. functions once) but it also has *the ability to be extended* as you,
  32. the programmer, sees fit.
  33.  
  34. Furthermore, your proposed pattern matching construct violates
  35. syntactic consistency - it looks like something else (witness the
  36. confusion those of us who have used Icon extensively have with
  37. 'seeing' what it is you want) - normal Icon exprssions.  It also
  38. changes the structure of the language so that there are places where
  39. arbitrary expressions are allowed and not patterns, and places where
  40. patterns are allowed and not arbitrary expressions (with very little
  41. syntactic clues as to what is needed where!).
  42.  
  43. Finally, you're introducing a 'sublanguage' into Icon (just as the
  44. pattern matching of SNOBOL was a sublanguage to SNOBOL).  Icon is
  45. already a fairly complex language, I'm not convinced that adding
  46. syntax to support a fairly limited operation is worth it, *especially*
  47. given that Icon already has a more powerful capability with its
  48. case expression.
  49.  
  50. } Steve Wampler proposed ...
  51. } >I guess the only real debate is whether to add it into the language
  52. } >or not:
  53. } >
  54. } >   case s := <expression> of {
  55. } >      match_syntax_tree(s,"let") : {a := s.arguments
  56. } >        ...
  57. } >      }
  58. } >
  59. } >   ...
  60. } >
  61. } >   procedure match_syntax_tree(s, op)
  62. } ># match a pattern, in this case, the pattern is simple...
  63. } >      if type(s) == "syntax_tree" & s.operator == "let" then
  64. } >         return s
  65. } >   end
  66. } >
  67. } >not as visually pleasing as a new syntax would be, but I contend
  68. } >this would be more flexible and generalizes better than fixed
  69. } >patterns would...
  70. } This stuff looks extremely awkward to me, in fact even more awkward
  71.  
  72. You find adding two assignment operators to your original syntax
  73. 'extremely' awkward?  Why?  More awkward, yes.  But I don't see
  74. that as 'extremely'!  Or is that you're writing your own pattern
  75. matching function(s) that you see as awkward?  Again, you write them
  76. once, hide them away in a library, and presto, no difference there
  77. with having them built into the language -- except that you can
  78. *change* them!
  79.  
  80. } than doing the pattern matching explicitly.  It would mean having
  81. } separate procedures (with different names, too!) for each constructor
  82. } AND combination of constants/unknowns.  My proposal was exactly
  83.  
  84. Nonsense.  I named it 'match_syntax_tree'.  You could just as easily
  85. call it 'pat_match', or whatever, and implement an entire pattern matcher
  86. in the one procedure.  Yes, you have to *write* the procedure
  87. to do what you want, but as I said, I consider that flexibility a net
  88. win (in fact, personally, I find it a *huge* win - I *like* being able
  89. to describe *exactly* what I want!)  And you only have to write it *once*,
  90. anyway...  Plus you can have different pattern-matchers for different
  91. contexts!
  92.  
  93. } aimed at removing that syntactic clumsiness.  As I said (again,
  94. } and again), that's exactly why compilers are so much easier to
  95. } write and read in functional languages.  The way to go would
  96. } probably be using the variant translator feature of Icon to do
  97. } the job.  Anyone interested?  (If I'm not all alone with this, I
  98. } might actually get around to doing it, some day ...)
  99.  
  100. Now that I can see, particularly as an experiment - you could get the
  101. syntax you want that way, and Icon already has the capability semantically.
  102. The current syntax just doesn't bother me enough to justify my time on
  103. it though.  You'll still have to write the 'awkward' procedures for
  104. actually doing the pattern matching, of course.
  105.  
  106. } Cheers :-> Chipsy
  107.  
  108. -- 
  109.     Steve Wampler
  110.     {....!arizona!naucse!sbw}
  111.     {sbw@turing.cse.nau.edu}
  112.